<#-- 这是一个 FreeMarker 模板文件 -->
from flask import Blueprint, Flask, request
from VisaManager import vm

${name} = Blueprint('${name}', __name__)
<#list configurations as configuration>
<#if configuration.name=="资源地址">
address: str = "${configuration.value}"
vm.add_resource(address)
</#if>
</#list>

<#list commands as command>

@${name}.route('/${name}/${command.name}', methods=['<#if command.action=="query">GET<#else >POST</#if>'])
def ${command.name}():
    '''
    ${command.description}
    '''
    <#list command.args as arg>
    ${arg.name} = request.args.get('${arg.name}')
    </#list>
    command_visa = f"${command.value}"
    <#if command.action=="query">
    res = vm.query(address, command_visa)
    return res
    <#else>
    vm.write(address, command_visa)
    return "${name} ${command.name} POST " + command_visa
    </#if>

</#list>

if __name__ == '__main__':
    app = Flask(__name__)
    app.register_blueprint(${name})
    app.run()
